#!/bin/bash
# Grades Test Suite Script (Brian Moran x00117596)

program="Grades"

echo ""
echo ""
echo "Testing Program Name: $program"
echo "Header column order changed for readability"  
echo "Case |  Input    |  Result  |  Expected               |  Observed"
echo "__________________________________________________________________________"

result=""

#Test Case 1
c=0
p1=0
p2=0
stdout=$(./Grades $p1 $p2 2>/tmp/stderr.txt)
stderr=$(cat /tmp/stderr.txt)
stderr=${stderr,,}

if [ "$stderr" = "fail" ];
then	result="OK    "
else	result="NOT OK"
fi

echo "  $c  |  $p1 $p2      |  $result  |  fail                   |  $stderr"

#Test Case 2
c=2
p1=40
p2=50
stdout=$(./Grades $p1 $p2 2>/tmp/stderr.txt)
stderr=$(cat /tmp/stderr.txt)
stderr=${stderr,,}

if [ "$stderr" = "component fail" ]; 
then	result="OK    "
else	result="NOT OK"
fi

echo "  $c  |  $p1 $p2    |  $result  |  component fail         |  $stderr"

#Test Case 3
c=3
p1=50
p2=40
stdout=$(./Grades $p1 $p2 2>/tmp/stderr.txt)
stderr=$(cat /tmp/stderr.txt)
stderr=${stderr,,}

if [ "$stderr" = "component fail" ]; 
then	result="OK    "
else	result="NOT OK"
fi

echo "  $c  |  $p1 $p2    |  $result  |  component fail         |  $stderr"

#Test Case 4
c=4
p1=50
p2=50
stdout=$(./Grades $p1 $p2 2>/tmp/stderr.txt)
stderr=$(cat /tmp/stderr.txt)
stderr=${stderr,,}

if [ "$stderr" = "pass" ]; 
then	result="OK    "
else	result="NOT OK"
fi

echo "  $c  |  $p1 $p2    |  $result  |  pass                   |  $stderr"

#Test Case 5
c=5
p1=100
p2=100
stdout=$(./Grades $p1 $p2 2>/tmp/stderr.txt)
stderr=$(cat /tmp/stderr.txt)
stderr=${stderr,,}

if [ "$stderr" = "pass with distinction" ]; 
then	result="OK    "
else	result="NOT OK"
fi


echo "  $c  |  $p1 $p2  |  $result  |  pass with distinction  |  $stderr"

#Test Case 6
c=6
stdout=$(./Grades 2>/tmp/stderr.txt)
stderr=$(cat /tmp/stderr.txt)
stderr=${stderr,,}

if [ "$stderr" = "invalid input" ]; 
then	result="OK    "
else	result="NOT OK"
fi
$(./Grades)
# $(./Grades >/dev/null)
#if [ $? != 0 ];
#	then stderr="NON-ZERO EXIT CODE"
#fi

echo "  $c  |  (none)   |  $result  |  invalid input          |  $stderr"

echo ""
echo ""

# Actual screen output for Grades version 1
# 
# sqa@sqa-VirtualBox:~/tosh/project/ro/ittqatest-read-only$ ./brian-grades.sh
# 
# 
# Testing Program Name: Grades
# Header column order changed for readability
# Case |  Input    |  Result  |  Expected               |  Observed
# __________________________________________________________________________
#  0  |  0 0      |  OK      |  fail                   |  fail
#  2  |  40 50    |  OK      |  component fail         |  component fail
#  3  |  50 40    |  OK      |  component fail         |  component fail
#  4  |  50 50    |  OK      |  pass                   |  pass
#  5  |  100 100  |  OK      |  pass with distinction  |  pass with distinction
#  6  |  (none)   |  NOT OK  |  invalid input          |  

# NOTE: Invalid Input is still not working and based on the the ./Grades (with no parameters) 
# a Segmentation fault (core dumped) is still happening
